import request from './request'

// 用户登录
export function login(data: { username: string; password: string }) {
  return request({
    url: '/auth/login',
    method: 'post',
    data
  })
}

// 用户注册
export function register(data: { username: string; password: string; name: string; phoneNumber: string; email: string }) {
  return request({
    url: '/users',
    method: 'post',
    data
  })
}

// 获取用户信息
export function getUserInfo(id?: string) {
  return request({
    url: id ? `/users/${id}` : '/users/profile',
    method: 'get'
  })
}

// 获取用户订单列表
export function getUserOrders(userId: string) {
  return request({
    url: `/orders/user/${userId}`,
    method: 'get'
  })
}

// 更新用户信息
export function updateUserInfo(id: string, data: { name?: string; phoneNumber?: string; avatar?: string; email?: string }) {
  return request({
    url: `/users/${id}`,
    method: 'put',
    data
  })
}

// 修改密码
export function changePassword(data: { oldPassword: string; newPassword: string }) {
  return request({
    url: '/users/password',
    method: 'put',
    data
  })
} 